<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:flex-start;padding-right: 30px;">
      <el-date-picker
        v-model="paytime"
        style="width:40%;margin-right:20px;padding-right: 30px;"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="开始日期"
        endPlaceholder="结束日期"
        valueFormat="yyyy-MM-dd"
        clearable
      >
      </el-date-picker>


      <el-input v-model="carid" style="width:20%;padding-right: 30px;" placeholder="车辆编号" clearable></el-input>

      <el-button size="mini" type="primary" @click="getlist">查询</el-button><el-button size="mini" type="info" @click="daochu">导出</el-button>

    </el-row>

    <el-divider></el-divider>
    <ptable id="tableExcel222ssss"
      :tableData="list"

      :pagobj.sync="pagobj"
    ></ptable>


  </div>
</template>

<script>

import ptable from '~/components/querysum/carfee/reimtable.vue';
import selectorg from '~/components/common/selectorg.vue';


import FileSaver from 'file-saver';
import XLSX from 'xlsx';

export default {
  components: {
    ptable, selectorg,
  },
  data() {
    return {

      ts: this.newStore(),
      list: [],
      list1: [],
      paytime: [],
      carid: '',

      showresub: false,
      nowapprovalid: '',
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      checkitem: {
        hash: {
          atype: '',
          id: '',
        },
      },
    };
  },
  mounted() {
    // this.getlist();
    // this.getitem();
  },
  methods: {
    daochu() {
      if (this.list.length == 0) {
        this.$message({
          type: 'error',
          message: '导出数据为空,无法导出',
        });
        return false;
      }

      const xlsxParam = { raw: true }; // 转换成excel时，使用原始的格式
      /* generate workbook object from table */
      const wb = XLSX.utils.table_to_book(
        document.querySelector('#tableExcel222ssss'),
        xlsxParam,
      );
      console.log(wb);
      /* get binary string as output */
      const wbout = XLSX.write(wb, {
        bookType: 'xlsx',
        bookSST: true,
        type: 'array',
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: 'application/octet-stream;charset=utf-8' }),
          'sheetjs.xlsx',
        );
      } catch (e) {
        if (typeof console !== 'undefined') console.log(e, wbout);
      }
      return wbout;
    },
    opendiag(item) {
      console.log(item);

      this.nowapprovalid = item.hash.aid;
      this.checkitem.hash.atype = '0102';
      this.checkitem.hash.id = item.hash.aid;
      this.reload('showresub');
    },
    reload(partsname) {
      // console.log(partsname);
      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    getselectorgid(val) {
      this.dept = val;
    },


    // 获取列表
    getlist() {
      // console.log("2222");
      const req = {
        handle: 'E0E144082D7A10B2DC400B628CBD4AE88CE64754FEC1E34A',
        repairtimes: this.paytime[0],
        repairtimee: this.paytime[1],
        servertimes: this.paytime[0],
        servertimee: this.paytime[1],
        oiltimes: this.paytime[0],
        oiltimee: this.paytime[1],
        carid: this.carid,


      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          this.list = ts.d.data.operation1;
        }
      });
    },
  },
};
</script>

